package com.kedacom.emptyproject

import android.app.Application
import com.kedacom.lego.fast.LegoFastApplication
import com.kedacom.lego.mvvm.LegoBaseApplication
import com.kedacom.util.LegoLog

/**
 *
 */
class MainApplication : LegoFastApplication() {
    companion object {
        var UserLoginMode = 1//显示几个模块，影响偏移位置

        val applicationContext: Application by lazy {
            LegoBaseApplication.getApplication()
        }
    }

    override fun onCreate() {
        super.onCreate()
        LegoLog.d("onCreate:初始化应用")
        //        MainDatabase.initDatabase(this);
        closeAndroidPDialog()
    }

    override fun isDebugMode(): Boolean {
        return BuildConfig.DEBUG
    }

    /**
     * 关闭 Android P 兼容性弹窗警告
     *
     *
     * https://blog.csdn.net/qinwendou/article/details/87911798
     */
    private fun closeAndroidPDialog() {
        try {
            val aClass = Class.forName("android.content.pm.PackageParser\$Package")
            val declaredConstructor = aClass.getDeclaredConstructor(
                String::class.java
            )
            declaredConstructor.setAccessible(true)
        } catch (e: Exception) {
            e.printStackTrace()
        }
        try {
            val cls = Class.forName("android.app.ActivityThread")
            val declaredMethod = cls.getDeclaredMethod("currentActivityThread")
            declaredMethod.isAccessible = true
            val activityThread = declaredMethod.invoke(null)
            val mHiddenApiWarningShown = cls.getDeclaredField("mHiddenApiWarningShown")
            mHiddenApiWarningShown.isAccessible = true
            mHiddenApiWarningShown.setBoolean(activityThread, true)
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }
}